package lore.miniwechat.web;

import lore.miniwechat.dto.BaseResponse;
import lore.miniwechat.dto.PageData;
import lore.miniwechat.entity.User;
import lore.miniwechat.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    UserService service;


    //查询
    @GetMapping("/users")
    public PageData<User> getUsers(
            @RequestParam(name="page",defaultValue = "1") Integer page,
            @RequestParam(name = "size",defaultValue = "10") Integer size){
        return service.getUserPageData(page, size);
    }
    //插入
    @PostMapping("/register")
    public BaseResponse createUser(@RequestBody User user){

        service.insert(user);
        return BaseResponse.success();
    }

    //修改
    @PutMapping("/user")
    public BaseResponse update(@PathVariable String uid){
        service.update(uid);
        return BaseResponse.success();
    }

    //删除（标记为不使用状态）
    @DeleteMapping("/user")
    public BaseResponse delete(@PathVariable String uid){
        service.deleteByPrimaryKey(uid);
        return BaseResponse.success();
    }

}
